#include <stdio.h>
#include <math.h>

int minSubArrayLen(int target, int *nums, int numsSize)
{
    int res = __INT_MAX__;
    int left = 0, subStrLen = 0, sum = 0;
    for (int right = 0; right < numsSize; ++right) {
        sum += nums[right];
        while (sum >= target) {
            res = fmin(res, right - left + 1);
            sum -= nums[left++];
        }
    }
    return res == __INT_MAX__ ? 0 : res;
}

void testminSubArrayLen()
{
    int nums[] = { 2, 3, 1, 2, 4, 3 };
    int numsSize = sizeof(nums) / sizeof(nums[0]);
    int target = 7;
    int result = minSubArrayLen(target, nums, numsSize);
    printf("Minimum subarray length with sum at least %d is %d\n", target, result);
}

int main()
{
    testminSubArrayLen();
    return 0;
}